package com.kim.oauth.common.model;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;

/**
 * 用户权限
 */
@Data
public class Authority implements GrantedAuthority, Comparable<Authority> {
    /**
     * 主键id
     */
    private Long id;

    /**
     * 键
     */
    private String name;

    /**
     * 值
     */
    private String value;

    /**
     * 组织机构
     */
    private String organize;

    /**
     * 拼接角色
     * <p>AUTH_ + {@code this.organize} + _ + {@code this.value}</p>
     * @return java.lang.String
     */
    @Override
    public String getAuthority() {
        return "AUTH_" + this.organize +
                "_" +
                this.value;
    }

    /**
     * 判断相同的方法
     * @param o 对比角色对象
     * @return int
     */
    @Override
    public int compareTo(Authority o) {
        //判断id是否相同
        if (this.id.equals(o.getId())) {
            return 0;
        }
        return -1;
    }
}